<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>优惠、免单</title>
<script
	src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link rel="stylesheet" href="/park/bootstrap/css/bootstrap.min.css" >
<link rel="stylesheet" href="/park/bootstrap/css/bootstrap-theme.min.css" >
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/park/bootstrap/js/bootstrap.min.js" ></script>
<script src="/park/js/layer_mobile/layer.js?v=1.6"></script>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js" ></script>
<script src="/park/js/vue.min.js"></script>
<style type="text/css">
#dataTable td,th{
	font-size:18px;
}
</style>
</head>
<body>
<div style="width: 96%;margin-left: 2%;margin-top: 30px;">
<div class="form-group">
    <input style="margin-top: 20px;font-size: 20px;line-height: 50px;height: 50px;" type="text" class="form-control" id="plate" placeholder="车牌号">
  </div>
  <button type="button" style="width: 100%;font-size: 20px;line-height: 40px;height: 50px;" class="btn btn-info" onclick="findData()" >查询</button>
</div>
<div style="width: 96%;margin-left: 2%;margin-top: 30px;">
<table class="table table-striped" id="dataTable" style="display: none;">
   <tbody>
    <tr>
    	<th>订单号</th>
    	<td v-text="datas.orderNo">20220305121000ZKZJ00201</td>
    </tr>
    <tr>
        <th>车牌号</th>
        <td v-text="datas.carLicense">沪S11111</td>
    </tr>
     <tr>
    	<th>停车时间</th>
    	<td v-text="datas.parkingHours">12 天 21 时 49 分</td>
    </tr>
     <tr>
    	<th>应缴金额</th>
    	<td v-text="datas.orderMoney" id="orderMoney" colspan="2">1400</td>
    </tr>
    <tr>
        <th>已免金额</th>
        <td v-text="datas.freeMoney" id="freeM">1400</td>
    </tr>
     <tr>
    	<th>入场时间</th>
    	<td v-text="datas.startTime">20221230130000</td>
    </tr>
    <tr>
    	<th style="padding-top: 20px">优惠金额</th>
    	<td><input class="form-control input-sm" type="text" id="freeMoney" style="font-size: 18px;line-height: 46px;height: 46px;" placeholder="请输入优惠金额"></td>
    </tr>
   </tbody>
</table>
</div>
<div id="but" style="width: 96%;margin-left: 2%;margin-top: 30px;display: none">
<table class="table ">
	 <tr>
    	<th> <button type="button" style="width: 100%;font-size:18px;line-height: 38px;height: 46px;" onclick="_go(0)" class="btn btn-success">全免</button></th>
    	<td> <button type="button" style="width: 100%;font-size:18px;line-height: 38px;height: 46px;" onclick="_go(1)" class="btn btn-warning">优惠</button></td>
    </tr>
</table>
</div>
<script type="text/javascript">
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}
var _d2 ='';
var _parkStatus = 0;
function _go(_index){
	var carLicense =  $('#plate').val();
	if(_parkStatus == 0){
		layer.open({
		    content: '没有查询在停订单！'
		    ,skin: 'msg'
		    ,time: 2 //2秒后自动关闭
		  });
		return;
	}
	if(carLicense==null||carLicense==''){
		layer.open({
		    content: '车牌号码未输入！'
		    ,skin: 'msg'
		    ,time: 2 //2秒后自动关闭
		  });
		return;
	}
    if($('#freeM').html() == "全免"){
        layer.open({
            content: '已全免，无需再次操作！'
            ,skin: 'msg'
            ,time: 2 //2秒后自动关闭
        });
        return;
    }
	var state = _index;
	var freeMoney = 0;
	if(state==1){
		freeMoney = Number($('#freeMoney').val());
		if(freeMoney==null||freeMoney==''){
			layer.open({
			    content: '优惠金额不能为空！'
			    ,skin: 'msg'
			    ,time: 2 //2秒后自动关闭
			  });
			return;
		}
        var orderMoney = Number($('#orderMoney').html());
		if(freeMoney > orderMoney){
            layer.open({
                content: '优惠金额不能大于订单金额！'
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
            return;
        }
		if(freeMoney < 0){
            layer.open({
                content: '优惠金额不能为负数！'
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
            return;
        }
        freeMoney = Number($('#freeMoney').val()) + Number($('#freeM').html());
        $.ajax({
            url:'/park/data/help/yh',
            data:'orderNo='+_orderNo+'&streetNo='+param+'&freeMoney='+freeMoney+'&state='+state,
            type:'post',
            dataType:'json',
            success:function(res){
                if('200'==res.code){
                    if(res.data.status==0){
                        if(state==1){
                            layer.open({
                                content:'操作成功！'
                                ,btn: "确定"
                                ,yes: function () {
                                    $('#freeMoney').val('');
                                    findData();
                                    layer.closeAll();
                                }
                            });
                        }else{
                            layer.open({
                                content:'操作成功！'
                                ,btn: "确定"
                                ,yes: function () {
                                    $('#freeMoney').val('');
                                    findData();
                                    layer.closeAll();
                                }
                            });
                        }
                    }else{
                        layer.open({
                            content: res.data.msg
                            ,skin: 'msg'
                            ,time: 2 //2秒后自动关闭
                        });
                    }
                }else{
                    layer.open({
                        content: '出错了！'
                        ,skin: 'msg'
                        ,time: 2 //2秒后自动关闭
                    });
                }
            }
        })
	}else{
        layer.open({
            content: '全免不可撤回，是否确认全免！'
            ,btn: ['确定','取消']
            ,yes: function () {
                layer.close(layer.index);
                $.ajax({
                    url:'/park/data/help/yh',
                    data:'orderNo='+_orderNo+'&streetNo='+param+'&freeMoney='+freeMoney+'&state='+state,
                    type:'post',
                    dataType:'json',
                    success:function(res){
                        if('200'==res.code){
                            if(res.data.status==0){
                                if(state==1){
                                    layer.open({
                                        content:'操作成功！'
                                        ,btn: "确定"
                                        ,yes: function () {
                                            $('#freeMoney').val('');
                                            findData();
                                            layer.closeAll();
                                        }
                                    });
                                }else{
                                    layer.open({
                                        content:'操作成功！'
                                        ,btn: "确定"
                                        ,yes: function () {
                                            $('#freeMoney').val('');
                                            findData();
                                            layer.closeAll();
                                        }
                                    });
                                }
                            }else{
                                layer.open({
                                    content: res.data.msg
                                    ,skin: 'msg'
                                    ,time: 2 //2秒后自动关闭
                                });
                            }
                        }else{
                            layer.open({
                                content: '出错了！'
                                ,skin: 'msg'
                                ,time: 2 //2秒后自动关闭
                            });
                        }
                    }
                })
            }
        });
    }
}
var param = getUrlParam('streetNo');
var _orderNo  ='';
function findData(){
	_parkStatus = 0;
	var plate = $('#plate').val();
	$.ajax({
		url:'/park/data/help/parking',
		data:'carLicense='+plate+'&streetNo='+param,
		type:'post',
		dataType:'json',
		success:function(res){
			if('200'==res.code){
				if(res.data.status==0){
					_parkStatus = 1;
					_orderNo = res.data.attr.orderNo;
					if(_d2==''){
		  				_d2 = new Vue({
		  					el : '#dataTable',
		  					data : {
		  						datas : res.data.attr
		  					}
		  				})
		  			}else{
		  				_d2.datas = res.data.attr
		  			}
					$('#dataTable').show();
					$('#but').show();
				}else{
					$('#dataTable').hide();
					layer.open({
					    content: res.data.msg
					    ,skin: 'msg'
					    ,time: 2 //2秒后自动关闭
					  });
				}
			}else{
				$('#dataTable').hide();
				layer.open({
				    content: '出错了！'
				    ,skin: 'msg'
				    ,time: 2 //2秒后自动关闭
				  });
			}
		}
	})
}
</script>
</body>
</html>